package Main;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;


class Main 
{
	
	static void usage() 
	{
		System.err.println("\nCompilo [-parse-only] [-type-only] *.jmm");
		System.exit(1);
	}


    public static void main(String[] arg) 
    {
    	boolean parse_only 	= false;
    	boolean type_only 	= false;
    	String filename 	= null;

		for (int i = 0; i < arg.length; i++) 
		{
			String a = arg[i];
			if (a.equals("-parse-only"))
			{
				parse_only = true;
			}
			else if (a.equals("-type-only"))
			{
				type_only = true;
			}
			else 
			{
				if (filename != null)
				{
					usage();
				}
				filename = a;
			}
		}
    	
    	//  On redirige la sortie normal, on n'affiche que la sortie d'erreur
    	System.setOut(new PrintStream(new ByteArrayOutputStream(), false));
    	System.setErr(System.err);
    	
    	Compilator oCompil = new Compilator();
    	oCompil.setParseOnly(parse_only);
    	oCompil.setTypeOnly(type_only);
    	int iStatus = oCompil.Compil(filename);
    	
    	System.exit(iStatus);
    }
}
